<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>disponibilidad</title>
<style type="text/css">
<!--
.style7 {font-size: 12px}
-->
</style>
<link href="tablas.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style15 {font-size: 12px; font-family: "Times New Roman", Times, serif; color: #CCCCCC; font-weight: bold; }
.style16 {font-size: 18px}
.style18 {color: #FF0000}
.style19 {font-family: "Times New Roman", Times, serif; font-weight: bold; color: #FF0000; }
.style22 {
	font-size: 18;
	color: #FFFFFF;
	font-weight: bold;
}
.style23 {font-size: 18px; color: #FFFFFF; }
.style24 {color: #000000}
.style25 {color: #FFFFFF; font-weight: bold; font-size: 18px; }
-->
</style>
<link href="estilacho.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	color: #993300;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #993300;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
	color: #FF0000;
}
.Estilo1 {font-size: 16px}
-->
</style>
</head>

<body>
 
  <? 
	include 'conexion.php';
   extract($_POST);
   extract($_GET);
   $ano=date('Y');
/*  $base= "ucg - copia";
	$conexion = mysql_connect("localhost","root","");
	mysql_select_db($base,$conexion);*/ 	?>

<table border="1" align="center" cellspacing="0" cellpadding="2">

<th colspan="9">TABLA DISPONIBILIDAD TOTAL</th>
    <tr>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Codigo</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Descripci&oacute;n</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Monto total Fondos</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Asignacion anual </strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Monto Comprometido</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>MontoCausado</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>MontoPagado</strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Saldo Financiero del Fondo </strong></div></td>
      <td bgcolor="#FFFFCC"><div align="center"><strong>Disponibilidad Presupuestaria </strong></div></td>
  </tr>
   <? 
   $sqlc=mysql_query("Select * from cuentas where ano='$ano' order by detalle",$conexion);
	 while ($regc= mysql_fetch_array($sqlc)){
	 
	 if ($regc[4]==0) $asig_anual=$regc[3];
	 else $asig_anual=$regc[4];
	 
    $asig_anual2=  number_format($asig_anual,2,",",".");
   
   $sql9=mysql_query("Select sum(monto) from fondo where fecha BETWEEN '$T1' and '$T2' and cuenta='$regc[1]' group by cuenta",$conexion);
   $reg9= mysql_fetch_array($sql9);
   
   $iva=mysql_query("SELECT sum(valor_iva)  FROM compra1, id_compra where compra1.cod_c=id_compra.cod_c and id_compra.cuenta_iva='$regc[1]' and compra1.anulado!=1 and compra1.fecha BETWEEN '$T1' and '$T2'  group by id_compra.cuenta_iva",$conexion);
	
	$ivas=0;	
	while ($iv= mysql_fetch_row($iva)) { 
	$ivas=$iv[0];
	$ivas2= number_format($ivas,2,",",".");
	
	
	}
   
    $com=mysql_query("SELECT sum(id_compra.cantidad*id_compra.pre_unit)  FROM compra1, id_compra where compra1.cod_c=id_compra.cod_c and id_compra.cuenta='$regc[1]' and compra1.anulado!=1 and compra1.fecha BETWEEN '$T1' and '$T2'  group by id_compra.cuenta",$conexion);
	
	$compra=0;	
	while ($compr= mysql_fetch_row($com)) { 
	$compra=$compr[0];
	$compra2= number_format($compra,2,",",".");
	
	
	}
   
   
   $pag=mysql_query("SELECT pago.fondo, pago.anulado, id_pago.cuenta, sum(id_pago.monto_s)  FROM pago, id_pago where pago.cod_p=id_pago.cod_p and id_pago.cuenta='$regc[1]' and pago.anulado!=1 and pago.fecha BETWEEN '$T1' and '$T2' group by id_pago.cuenta",$conexion);
		
	$sumsaldo=0;
	while ($pago= mysql_fetch_row($pag)) { 	
	$sumsaldo=$pago[3];
	$sumsaldo2= number_format($sumsaldo,2,",","."); }
	
	$sal_fin=$reg9[0]-$sumsaldo; 
	  $sal_fin2= number_format($sal_fin,2,",",".");
	
	$sal_pre=$asig_anual-$compra; 
	  $sal_pre2= number_format($sal_pre,2,",",".");
	
	
	
	?>
    <tr>
      <td><? echo $regc[1]; ?></td>
      <td><? echo $regc[2]; ?></td>
      <td><div align="right" class="style7 style7 Estilo1"><? 
	  if($reg9[0]=="") echo '0.00'; else echo $reg9[0]; ?></div></td>
      <td><div align="right" class="style7 style7 Estilo1"><? echo $asig_anual2; ?></div></td>
      <? $sqli=mysql_query("Select * from cuenta_iva where cuenta_iva='$regc[1]'",$conexion);
	     $regi= mysql_fetch_array($sqli); 		 
		 if ($regi){?>
      <td><div align="right" class="style7 style7 Estilo1"><?
	  if ($ivas==0) echo $ivas; else echo $ivas2; ?></div></td>
      <td><div align="right" class="style7 style7 Estilo1"><?
	  if ($ivas==0) echo $ivas; else echo $ivas2; ?></div></td>
      <? }
	  else { ?>
      <td><div align="right" class="style7 style7 Estilo1"><?
	  if ($compra==0) echo $compra; else echo $compra2; ?></div></td>
      <td><div align="right" class="style7 style7 Estilo1"><?
	  if ($compra==0) echo $compra; else echo $compra2; ?></div></td>
      <? } ?>
      <td><div align="right" class="style7 style7 Estilo1"><? 
	  if ($sumsaldo==0) echo $sumsaldo; else echo $sumsaldo2; ?></div></td>
      <td><div align="right" class="style7 style7 Estilo1"> <? echo $sal_fin2; ?> </div></td>
      <td><div align="right" class="style7 style7 Estilo1"><?  echo $sal_pre2; ?> </div></td>
    </tr> 	
	<? }?>	
</table>
<div align="center">
<a href="disponibilidad1.php">Regresar</a>
</div>
</body>
</html>
